// Drummer Server
// by Andrea Bianchi
// drummer.alsoplantsfly.com

/*
Copyright (C) 2009, Andrea Bianchi

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

//import promidi.*;
import java.util.HashMap;
import  sun.audio.*;  
import  java.io.*;
import java.io.File;



class DrummerPlayer implements Runnable
{

  // Don't modify this array: order of string is important (the order is mapped with the signals received by network"
  private String [] Instruments={ "bass1", "bass2", "hihat1", "hihat2", "snare1", "snare2", "crash1", "crash2", "tom1", "tom2", "tom3", "tom4" };
 

  public void play (int id, String kit)
  {
    try{
      this.filePath= dataPath("") + "/sound/" + kit + "/" + idToInstrumentName (id) +".wav";
      new Thread (this).start();
    }catch (Exception e)
    {
     // somehting got wrong this time: don't care 
    }
  }


  public void run ()
  { 
    try{          
      File file = new java.io.File(filePath);
      AudioClip sound = Applet.newAudioClip(file.toURL());
      sound.play();
    
    
    }
    catch (Exception e){
    }     
  }
  


  private String idToInstrumentName (int id) throws Exception
  {
    return Instruments[id-1]; //exception if out of bounds
  }
  
  
  private String filePath; 
}






